package com.miyu.client1.test;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class testJAVA{
    public static void main(String[] args) {
        //知道类的名称
        String methodName = "eat";//方法名字
        String methodAglet = "苹果";//方法参数
        try {

            Object obj = Class.forName("com.miyu.client1.test.Dog").newInstance();
            if(obj.equals(null))return;
            Method[] methods = obj.getClass().getMethods();
            int i = 0;
            for (i = 0; i < methods.length; i++) {
                if(methods[i].getName().equals(methodName)) break;
            }
          String rs = (String) methods[i].invoke(obj, new Object[]{methodAglet});
            System.out.println(rs);
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch ( InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
//class Dog{
//    Dog(){
//    }
//    public void eat(String name){
//        System.out.println("吃"+name);
//    }
//}
